Skip to content

Optimised database registration logic in CLEM workflow#787

Merged
tieneupin merged 4 commits intomainfrom
clem-fixes
Apr 30, 2026
Merged

Optimised database registration logic in CLEM workflow#787
tieneupin merged 4 commits intomainfrom
clem-fixes

Conversation

@tieneupin
Copy link
Copy Markdown
Contributor

@tieneupin tieneupin commented Apr 20, 2026

Fixes a couple of issues with the database registration logic in the CLEM workflow:

Handle the possibility of there being multiple atlas images associated with a grid
We occasionally run into situations where more than one image set for a grid meets the criteria to be registered as an atlas, which breaks the workflow because the SQL query expects a single matching database entry or no result.

This can be resolved by returning all matching atlas entries, sorted by insertion order. The latest one is used to perform the ISPyB updates. Because the GridSquare and DataCollectionGroup entries are re-updated for every new image set received, all entries for a given sample grid will be re-updated correctly with reference to the last atlas registered.

Accidental insert when updating ImagingSite entries after registering GridSquare entries
There was a race condition between when the ImagingSite entries from _register_clem_imaging_site are committed and when they are queried in _register_dcg_and_atlas. This lead to the creation of duplicate ImagingSite entries in the database. This can be fixed by modifying the subsequent helper functions to use the registered ImagingSite entry from _register_clem_imaging_site instead of querying it from the database.

Less aggressive commits
In register_grid_square, db.commit() was previously run multiple times within a single for loop. By moving it out of the loop, this should improve performance.

@tieneupin tieneupin self-assigned this Apr 20, 2026
@tieneupin tieneupin added bug Something isn't working server Relates to the server component cryo-clem Part of the cryo-CLEM pipeline extension labels Apr 20, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 20, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.84%. Comparing base (3d23916) to head (13bf5aa).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #787      +/-   ##
==========================================
+ Coverage   50.72%   50.84%   +0.12%     
==========================================
  Files          96       96              
  Lines       10059    10082      +23     
  Branches     1322     1337      +15     
==========================================
+ Hits         5102     5126      +24     
+ Misses       4690     4687       -3     
- Partials      267      269       +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…te a new ImagingSite entry, but should fail loudly if no entry was found; move the 'commit()' command out of the for loop
@tieneupin tieneupin changed the title Adjust logic to CLEM workflow to support multiple registered atlases Optimise database registration logic in CLEM workflow Apr 21, 2026
@tieneupin tieneupin changed the title Optimise database registration logic in CLEM workflow Optimised database registration logic in CLEM workflow Apr 21, 2026
…entry; modified the subsequent helper functions to use the returned ImagingSite entry instead of performing new queries
Copy link
Copy Markdown
Contributor

@stephen-riggs stephen-riggs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks cleaner than before, thanks for making the discussed changes

@tieneupin tieneupin merged commit 0453603 into main Apr 30, 2026
17 checks passed
@tieneupin tieneupin deleted the clem-fixes branch April 30, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cryo-clem Part of the cryo-CLEM pipeline extension server Relates to the server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants